package org.example.musicproject.service.impl;

import org.example.musicproject.dao.CommentsDao;
import org.example.musicproject.dao.impl.CommentsDaoImpl;
import org.example.musicproject.entity.Comments;
import org.example.musicproject.service.CommentsService;
import org.example.musicproject.util.DButil;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;

/**
 * 创建人:黄庭萍
 * 创建时间: 2024/12/16 19:43
 * 创建类型: CommentsServiceImpl
 */
public class CommentsServiceImpl implements CommentsService {
    final CommentsDao dao = new CommentsDaoImpl();
    @Override
    public List<Comments> all() {
        return dao.all();
    }

    @Override
    public Comments byId(int id) {
        return dao.byId(id);
    }

    @Override
    public int add(Comments comments) {
        return dao.add(comments);
    }

    @Override
    public int updateDelReason(int cid, String delReason) {
        return dao.updateDelReason(cid, delReason);
    }

    @Override
    public List<Comments> getAllCommentsBySongId(int soid) {
        try {
            return dao.getCommentsBySongId(soid);
        } catch (RuntimeException e) {
            throw new RuntimeException("查询评论失败", e);
        }
    }

    @Override
    public boolean delete(int cid, String delReason) {
        try {
            dao.delete(cid, delReason);
            return true;

            // 通知用户（此部分取决于您的通知机制）
//        notifyUser(uid, "您的评论已被删除，原因：" + delReason);

        }catch (Exception e) {
            return false;
        }
    }

    /**
     * 实现通知逻辑（例如发送邮件或推送通知）
     * @param uid 用户编号
     * @param message 通知信息(删除评论通知)
     */
    private void notifyUser(String uid, String message) {
        // 实现通知逻辑（例如发送邮件或推送通知）
        System.out.println("已通知用户 " + uid + "：" + message);
    }
}
